//app.js
App({
  onLaunch: function () {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function (result) {
          var l = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + that.globalData.appId + '&secret=' + that.globalData.appSecret + '&js_code=' + result.code + '&grant_type=authorization_code';
          wx.request({
            url: l,
            data: {},
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT    
            // header: {}, // 设置请求的 header    
            success: function (res) {
              wx.setStorageSync('openId', res.data.openid)
            }
          });
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              wx.setStorageSync('userInfo', res.userInfo)
            }
          })
        }
      })
    }
  },
  onShow: function () {
    var openId = wx.getStorageSync('openId');
    var userInfo = wx.getStorageSync('userInfo');
    wx.request({
      url: this.globalData.host + '/customerApi/customer', //仅为示例，并非真实的接口地址
      data: {
        thirdpartyType: '1',
        thirdpartyId: openId,
        gender: userInfo.gender,
        nickname: userInfo.nickName,
        photo: userInfo.avatarUrl
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
      }
    }) 
  },
  globalData: {
    appId: 'wx71cf45bf014d82b5',
    appSecret: 'bcd12d3d8b669ab87bed6b10406fb73b',
    host: 'https://cloud.kaaction.com/kaaction/api/v1',
    userInfo: null,
    image: "https://cloud.kaaction.com"
  }
})